package com.putprize.semantic.service;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.putprize.semantic.SemanticPoser;

public class SemanticPosServlet extends HttpServlet {

	private static final long serialVersionUID = -6907522197223111963L;
	
	private SemanticPoser pos;
	
	public SemanticPosServlet(SemanticPoser p){
		pos = p;
	}
	
	@Override
	protected void doGet(HttpServletRequest rq, HttpServletResponse rp)
			throws ServletException,IOException{
		process(rq,rp);
	}
	
	@Override
	protected void doPost(HttpServletRequest rq, HttpServletResponse rp)
			throws ServletException,IOException{
		process(rq,rp);
	}
	
	void process(HttpServletRequest rq, HttpServletResponse rp)
			throws ServletException, IOException {

        rq.setCharacterEncoding("UTF-8");
		rp.setCharacterEncoding("UTF-8");
		rp.setContentType("text/html");
		
		String line = rq.getParameter("line");
		
		rq.setCharacterEncoding("UTF-8");
		PrintWriter out = rp.getWriter();
		
		String res = pos.process(line);
		
		out.println(res.trim());
	}

}
